package com.example.hotelsystem.controller.city;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.hotelsystem.entity.CityImage;
import com.example.hotelsystem.entity.UserRole;
import com.example.hotelsystem.result.Result;
import com.example.hotelsystem.service.CityImageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.xml.crypto.Data;
import java.util.Date;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Lee
 * @since 2021-04-06
 */
@RestController
@RequestMapping("/hotelsystem/cityImage")
@Api(tags = "城市图片接口控制器")
public class CityImageController {
    @Autowired
    CityImageService cityImageService;

    @PostMapping("/getImageList")
    @ApiOperation("通过城市获得绑定图片")
    public Result getImageList(Long cityId){
        try {
            QueryWrapper<CityImage> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("city_id",cityId);
            List<CityImage> list = cityImageService.list(queryWrapper);
            return Result.success(list);
        }catch (Exception e){
            return Result.error(e.getMessage());
        }
    }

    @PostMapping("/add")
    public Result addCityImage(CityImage cityImage){
        try {
            Date date = new Date();
            cityImage.setCreateTime(date);
            cityImageService.save(cityImage);
            return Result.success("操作成功");
        }catch (Exception e){
            return Result.error(e.getMessage());
        }
    }

//    @PostMapping("/update")
//    public Result updateCityImage(CityImage cityImage){
//        try {
//            cityImageService.updateById(cityImage);
//            return Result.success("操作成功");
//        }catch (Exception e){
//            return Result.error(e.getMessage());
//        }
//    }

    @PostMapping("/remove")
    public Result removeCityImage(Long id){
        try {
            cityImageService.removeById(id);
            return Result.success("操作成功");
        }catch (Exception e){
            return Result.error(e.getMessage());
        }
    }
}

